package cn.xn.hrms.api.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import cn.xn.hrms.api.dto.res.MenuChildDTO;
import cn.xn.hrms.api.dto.res.MenuDTO;
import cn.xn.hrms.domain.service.MenuService;
import cn.xn.hrms.domain.utils.ResultVo;
import cn.xn.hrms.api.dto.res.UserMenuDTO;
import io.swagger.annotations.ApiOperation;

/**
 * @author: ysz
 * @date: 2023/07/24
 **/
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;


    /**
     * 获取用户菜单列表
     *
     * @return
     */
    @ApiOperation("获取登录用户菜单列表")
    @GetMapping("/userMenuList")
    public UserMenuDTO userMenuList() {
        return menuService.getUserMenuList();
    }


    /**
     * 获取树形菜单列表
     *
     * @return
     */
    @ApiOperation("获取树形菜单列表")
    @GetMapping("/allMenu")
    public List<MenuChildDTO> getMenuList() {
        return  menuService.getMenuList(null);
    }

    /**
     * 新增菜单
     *
     * @param menuDTO
     * @return
     */
    @ApiOperation("新增菜单")
    @PostMapping("/add")
    @RequiresRoles("admin")
    public ResultVo create(@RequestBody MenuDTO menuDTO) {
        menuService.add(menuDTO);
        return ResultVo.success();

    }

    /**
     * 删除菜单
     *
     * @param id
     * @return
     */
    @ApiOperation("删除菜单")
    @DeleteMapping("/{id}/delete")
    @RequiresRoles("admin")
    public ResultVo deleteMenu(@PathVariable Long id) {
        menuService.deleteMenu(id);
        return ResultVo.success();

    }

    /**
     * 修改菜单
     *
     * @param menuDTO
     * @return
     */
    @ApiOperation("修改菜单")
    @PutMapping("/update")
    @RequiresRoles("admin")
    public ResultVo update(@RequestBody MenuDTO menuDTO) {
        menuService.update(menuDTO);
        return ResultVo.success();

    }


}
